/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Vue;

import Modele.ModeleImage;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Soufiane GARCH
 */
public class VueBouton extends JPanel implements ActionListener{

    
    private JButton diapo;
    private JButton zoom;
    private JButton dezoom;
    private JButton negatif;
    private JButton flou;
    private JButton rotation;
    private JButton gris;
    private JButton accentue;
    private JButton accentue2;
    private VuePrincipale vuePrincipale;
    
    public VueBouton(VuePrincipale vP){
        this.vuePrincipale = vP;
        this.addBoutons();
    }
    
    private void addBoutons(){
        this.setLayout(new FlowLayout());
        
        this.setDiapo();
        //this.add(diapo);
        
        this.setZoom();
        this.add(zoom);
        
        this.setDezoom();
        this.add(dezoom);
        
        this.setFlou();
        this.add(flou);
        
        this.setNegatif();
        this.add(negatif);
        
        this.setRotation();
        this.add(rotation);
        
        this.setGris();
        this.add(gris);
        
        this.setAccentue();
        this.add(accentue);
        
        this.setAccentue2();
        this.add(accentue2);
    }
    
    private void setDiapo(){
        diapo = new JButton();
        diapo.setText("Diaporama");
        //diapo.setIcon(new ImageIcon("diapo.gif"));
        //diapo.setVerticalTextPosition(SwingConstants.LEFT);
        //diapo.setHorizontalTextPosition(SwingConstants.CENTER);
        diapo.addActionListener(this);
    }
    
    private void setGris(){
        gris = new JButton();
        gris.setText("Effet Gris");
        gris.addActionListener(this);
    }
    
    private void setZoom(){
        zoom = new JButton();
        zoom.setText("  Zoomer ");
        //zoom.setIcon(new ImageIcon("diapo.gif"));
        //zoom.setVerticalTextPosition(SwingConstants.LEFT);
        //zoom.setHorizontalTextPosition(SwingConstants.CENTER);
        zoom.addActionListener(this);
    }
    
    private void setAccentue(){
        accentue = new JButton();
        accentue.setText("Accentuer");
        //zoom.setIcon(new ImageIcon("diapo.gif"));
        //zoom.setVerticalTextPosition(SwingConstants.LEFT);
        //zoom.setHorizontalTextPosition(SwingConstants.CENTER);
        accentue.addActionListener(this);
    }
    
    private void setAccentue2(){
        accentue2 = new JButton();
        accentue2.setText("Craie");
        //zoom.setIcon(new ImageIcon("diapo.gif"));
        //zoom.setVerticalTextPosition(SwingConstants.LEFT);
        //zoom.setHorizontalTextPosition(SwingConstants.CENTER);
        accentue2.addActionListener(this);
    }
    
    private void setDezoom(){
        dezoom = new JButton();
        dezoom.setText("Dézoomer ");
        //dezoom.setIcon(new ImageIcon("diapo.gif"));
        //dezoom.setVerticalTextPosition(SwingConstants.LEFT);
        //dezoom.setHorizontalTextPosition(SwingConstants.CENTER);
        dezoom.addActionListener(this);
    }
    
    private void setNegatif(){
        negatif = new JButton();
        negatif.setText("Negatif ");
        //negatif.setIcon(new ImageIcon("diapo.gif"));
        //negatif.setVerticalTextPosition(SwingConstants.LEFT);
        //negatif.setHorizontalTextPosition(SwingConstants.CENTER);
        negatif.addActionListener(this);
    }
    
    private void setFlou(){
        flou = new JButton();
        flou.setText("  Flou   ");
        //flou.setIcon(new ImageIcon("diapo.gif"));
        //flou.setVerticalTextPosition(SwingConstants.LEFT);
        //flou.setHorizontalTextPosition(SwingConstants.CENTER);
        flou.addActionListener(this);
    }
    
    private void setRotation(){
        rotation = new JButton();
        rotation.setText("Rotation ");
        //rotation.setIcon(new ImageIcon("diapo.gif"));
        //rotation.setVerticalTextPosition(SwingConstants.LEFT);
        //rotation.setHorizontalTextPosition(SwingConstants.CENTER);
        rotation.addActionListener(this);
    }
    
    @SuppressWarnings("static-access")
    public void actionPerformed(ActionEvent e) {
        
        Object source = e.getSource();
        
        if (source == negatif){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.negative();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }//Fin Negatif
        else if (source == flou){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.flou();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }//Fin Flou
        else if (source == rotation){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                JOptionPane d = new JOptionPane();
                String angle;
                angle = d.showInputDialog(this,"Donner l'angle de rotation","0");
                if (angle != null){
                    try {
                        int nombre = Integer.parseInt(angle);
                        mI.rotation(new Integer(nombre));
                        vuePrincipale.getPanelPhoto().repaint();
                    }catch (NumberFormatException nfe){
                        JOptionPane d2 = new JOptionPane();
                        d2.showMessageDialog(this,"L'angle que vous avez entré n'est pas un entier","Rotation",JOptionPane.WARNING_MESSAGE);
                    } 
                }      
            }
        }//Fin Rotation
        else if (source == zoom){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.zoom();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }//Fin zoom
        else if (source == dezoom){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.dezoom();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }//Fin dezoom
        else if (source == accentue){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.sharpen();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }//Fin accentue
        else if (source == gris){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.gris();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }//Fin gris
        else if(source == accentue2){
            ModeleImage mI = vuePrincipale.getImageActuel();
            if (mI == null){
                JOptionPane d = new JOptionPane();
                d.showMessageDialog(this,"Aucune image selectionnée","Traitement image",JOptionPane.WARNING_MESSAGE);        
                return;
            }else{
                mI.edgeDetect();
                vuePrincipale.getPanelPhoto().repaint();
            }
        }
    }
    
}
